package com.rongchuan.wt.job;

import com.alibaba.fastjson.JSON;
import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import com.rongchuan.wt.enums.CommonRedisKey;
import com.rongchuan.wt.mapper.EmployeeMapper;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

@Component
@Setter
@Getter
@RefreshScope
@Slf4j
public class EmployeeJob implements SimpleJob {
    @Override
    public void execute(ShardingContext shardingContext) {

    }

//    @Value("${jobCron.EmployeeJob}")
//    private String cron;
//
//    @Autowired
//    private StringRedisTemplate redisTemplate;
//    @Autowired
//    private EmployeeMapper employeeMapper;
//
//    @Override
//    public void execute(ShardingContext shardingContext) {
//        doWork();
//    }
//
//    private void doWork() {
//        String key = CommonRedisKey.EMPLOYEE.toString();
//        //删除所有的key
//        redisTemplate.delete(key);
//        employeeMapper.selectAll().forEach(employee -> {
//            redisTemplate.opsForHash().put(key, employee.getId().toString(), JSON.toJSONString(employee));
//        });
//    }
}
